/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package kphoto.mc.testing;

import com.itextpdf.text.*;
import com.itextpdf.text.pdf.FdfReader;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.text.pdf.PdfReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 *
 * @author AndreasK
 */
public class DocumentTester {
    
    // TODO: Add a customer class and receive customer once from DB for invoice creation.
    
    public static void Start(String customerId) throws FileNotFoundException, DocumentException{
        
        Document document = new Document(PageSize.A4);

        PdfWriter.getInstance(document, new FileOutputStream("HelloWorldOpenGeekz.pdf"));
        document.setMargins(36, 36, 10, 144);

        document.open();
       
        Font headerFont = new Font(Font.FontFamily.HELVETICA, 14);
        headerFont.setColor(BaseColor.GRAY);
        Font headerFont2 = new Font(Font.FontFamily.HELVETICA, 10);
        headerFont2.setColor(BaseColor.GRAY);
        
        Paragraph paragraphTop = new Paragraph("Andreas Alexander Kaczmarek", headerFont);
        paragraphTop.setAlignment(2);
        paragraphTop.setFont(headerFont2);
        paragraphTop.add("\nJennerstrasse 15a\n84419 Schwindegg\nTel: +49 (8082) 2716347\nMobil: +49 (172) 1897798\nEmail: photo@kaczmarek-photo.de\n\n");
        document.add(paragraphTop);
        
        Paragraph spacing = new Paragraph("\n\n\n");
               
        Rectangle rectangleTop = new Rectangle(30, 730, 565, 729);
        rectangleTop.setBackgroundColor(BaseColor.GRAY);
        document.add(rectangleTop);
        Rectangle rectangleBottom = new Rectangle(30, 45, 565, 44);
        rectangleBottom.setBackgroundColor(BaseColor.GRAY);
        document.add(rectangleBottom);
        
        Font returnAdressFont = new Font(Font.FontFamily.HELVETICA, 7);
        returnAdressFont.setStyle(Font.ITALIC);
        Paragraph returnAdress = new Paragraph("\nAndreas Kaczmarek - Jennerstrasse 15a - 84419 Schwindegg\n\n", returnAdressFont);
        document.add(returnAdress);
        
        Paragraph customerAddress = GetCustomerAddress(customerId);
        document.add(customerAddress);
        
        document.add(spacing);
        
        Paragraph infoLine = GetInfoLine(customerId);
        document.add(infoLine);
        
        document.add(spacing);
        //Paragraph correspondance = GetCorrespondance(customerId);
        
        // TODO: Check how to add at a certain Position.
        Paragraph bottomParagraph = new Paragraph("This is the Bottomline");
        document.add(bottomParagraph);
        
//        document.newPage();
//        Paragraph paragraphB = new Paragraph("Fast brown ");
//        paragraphB.add("Fox jumps over the lazy dog second time.");
//        document.add(paragraphB);
         
         
         
         
         
         
        document.close();
        }
    
    public static void LoadBackground() throws FileNotFoundException, IOException
    {
        PdfReader reader = new FdfReader(new FileInputStream("style.pdf"));
        Document doc = new Document(PageSize.A4);
        
    }

    private static Paragraph GetCustomerAddress(String customerId) {
        Font addressFont = new Font(Font.FontFamily.HELVETICA, 12);
        Paragraph addressParagraph = new Paragraph();
        addressParagraph.setFont(addressFont);
        addressParagraph.add("Musterfirma\nMax Mustermann\nMusterstrasse 12\n\n12345 Musterstadt");
        return addressParagraph;
    }

    /*
     * Use a table to format these strings!!!
     */
    private static Paragraph GetInfoLine(String customerId) {
        Font infoLineFont = new Font(Font.FontFamily.COURIER, 11);
        Paragraph infoLine = new Paragraph();
        infoLine.setFont(infoLineFont);
        infoLine.setAlignment(2);
        infoLine.add("Kundennummer:                S01\n");
        infoLine.add("Rechnungsnummer:    S01-2011-001\n");
        infoLine.add("Datum:                30.03.2011\n");
        
        return infoLine;                
    }

    /*
     * Use a table to format this and receive data from database
     */
    private static Paragraph GetCorrespondance(String customerId) {
        throw new UnsupportedOperationException("Not yet implemented");
    }
}
